<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
        <link rel="stylesheet" type="text/css" href="jquery/css/ui-lightness/jquery-ui-1.8.13.custom.css"/>
        <script type="text/javascript" src="jquery/js/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" src="jquery/js/jquery-ui-1.8.13.custom.min.js"></script>
        <title>EasyCharts - Adminpanel</title>
        <script type="text/javascript">
            $(document).ready(function() {
                $dialog = $('<div></div>')
                .dialog({
                    autoOpen: false,
                    modal: true,
                    position: ['center', 60],
                    draggable: false,
                    resizable: false,
                    title: 'Title',
                    width: '460'
                });
            });
            
            function opendialog(userID, userName){
                $dialog.load('dialog_adminedituser.php');
                $dialog.dialog({title: 'User: ' + userID + ' - ' + userName});
                $dialog.dialog('open');
                // prevent the default action, e.g., following a link
                return false;
            }
        </script>
    </head>
    <body>
        <div id="content" style="min-width: 1200px; max-width: 1200px;">
            <?php
            // Starts the session
            session_start();

            // Includes
            include 'validateadmin.php';
            include 'header.php';
            include 'menu.php';
            include 'dbConfig.php';

            // Select Query
            $q = "SELECT ID, Email, Name, Creationdate FROM users order by Creationdate";

            // Run the Query
            $r = mysql_query($q);
            ?>
            <div id="pagecontent" style="height: 100%; padding-bottom: 26px;">
                <div id="contentbox" style="width: 900px;">
                    <h2 style="margin-top: 0px; border-bottom: 1px solid #cccccc; width: 100%;"><img src="img/page_edit.png"/> Website Administration</h2>
                    <div style="width: 100%; clear: none; float: left;">
                        <h3 style="margin-top: 15px; margin-bottom: 0px; width: 100%;">Registered users (<?php echo mysql_num_rows($r) ?>) </h3>
                        <div style="border: 1px solid #cccccc; background-color: white; margin-top: 6px; padding: 10px; border-radius: 6px;">
                            <div style="height: 30px; border-bottom: 1px solid #cccccc; padding-bottom: 4px; padding-left: 6px;">
                                <div style="height: 100%; width: 33%; float: left;">
                                    <label style="position: relative; top: 10px;" ><b>Email</b></label>
                                </div>
                                <div style="height: 100%; width: 40%; float: left;">
                                    <label style="position: relative; top: 10px;" ><b>Name</b></label>
                                </div>
                                <div style="height: 100%; width: 18%; float: left;">
                                    <label style="position: relative; top: 10px;" ><b>Registrationdate</b></label>
                                </div>
                                <div style="height: 100%; width: 6%; float: right;">
                                    <label style="position: relative; top: 10px;" ><b>Edit</b></label>
                                </div>
                            </div>
                            <?php
                            // Create a Div for each user in the database
                            while ($obj = mysql_fetch_object($r)) {
                                // Create session variables
                                $user_id = $obj->ID;
                                $user_name = $obj->Name;
                                $user_email = $obj->Email;
                                $user_creationdate = $obj->Creationdate;
                                ?>
                                <div onmouseover="this.style.backgroundColor='#F0F0F0';" onmouseout="this.style.backgroundColor='transparent';" style="height: 30px; border-bottom: 1px solid #eee; padding-bottom: 4px; padding-left: 6px;">
                                    <div style="height: 100%; width: 33%; float: left;">
                                        <label style="position: relative; top: 10px;" ><?php echo $user_email ?></label>
                                    </div>
                                    <div style="height: 100%; width: 40%; float: left;">
                                        <label style="position: relative; top: 10px;" ><?php echo $user_name ?></label>
                                    </div>
                                    <div style="height: 100%; width: 18%; float: left;">
                                        <label style="position: relative; top: 10px;" ><?php echo $user_creationdate ?></label>
                                    </div>
                                    <div style="height: 100%; width: 6%; float: right;">
                                        <img onclick="opendialog('<?php echo $user_id ?>', '<?php echo $user_name ?>')" src="img/user_edit.png" style="position: relative; top: 10px; margin-left: 14px; cursor: pointer;"/>
                                    </div>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
            // Close mysql
            mysql_close($ms);
            include 'footer.php';
            ?>
        </div>
    </body>
</html>
